import { ref } from "vue"

// 获取设备安全距离
export const useSafeAreaInsets = () => {
	// 系统信息
	// const systemInfo = ref({
	// 	windowWidth: 0,
	// 	windowHeight: 0,
	// 	safeArea: {
	// 		top: 0,
	// 		right: 0,
	// 		bottom: 0,
	// 		left: 0
	// 	},
	// 	safeAreaInsets: {}
	// })
	// const safeAreaInsets = ref({})
	let systemInfo;
	let safeAreaInsets;
	
	// #ifdef MP-WEIXIN
	// 微信小程序使用新的API
	systemInfo = uni.getWindowInfo()

	safeAreaInsets = systemInfo.safeArea
	  ? {
	      top: systemInfo.safeArea.top,
	      right: systemInfo.windowWidth - systemInfo.safeArea.right,
	      bottom: Math.abs((systemInfo.windowHeight - systemInfo.safeArea.bottom)),
	      left: systemInfo.safeArea.left,
	    }
	  : null
	// #endif
	
	// #ifndef MP-WEIXIN
	// 其他平台继续使用uni API
	systemInfo = uni.getSystemInfoSync()
	safeAreaInsets = systemInfo.safeAreaInsets
	// #endif
	
	return {
		systemInfo,
		safeAreaInsets
	}
}